package davidlauzon.activerecord;

import java.sql.SQLException;

import davidlauzon.activerecord.connection.ConnectionAdapter;
import davidlauzon.activerecord.recordset.RecordSet;
import junit.framework.TestCase;

public abstract class AbstractTestCase extends TestCase
{
    /*********************************************************************************************
     * INTERNAL METHODS
     *********************************************************************************************/

    protected abstract ConnectionAdapter getAdapter();
    
    protected void log(String funcName, Object message) {
        System.out.println(getClass().getSimpleName() + "::" + funcName + "() " + message);
    }
    

    protected int printRecords() throws SQLException {
        RecordSet set;
        int size = 0;
        
        long   l;
        String s;
        float  f;
        int    i;
        
        set = getAdapter().executeQuery( Constants.SELECT_ALL_PEOPLE);
        
        while ( set.next() ) {
            l = set.getLong(0);
            s = set.getString(1);
            f = set.getFloat(2);
            i = set.getInt(3);
            size++;
            log("listing db records", "\t=> #" + l + " " + s + ": " + f + " ; " + i);
        }
        set.close();
        
        return size;
    }
    
    protected void logSql(String sql, long result) {
        log("sql", "[" + result + "] =>\t" + sql);
    }
}
